package com.wingstudio.springcloud.result;

import org.springframework.http.HttpStatus;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author ITcz
 * @Data 2020-12-08 - 20:14
 */

public class R extends HashMap<String, Object> {

    private final static String CODE = "code";

    private final static String MSG = "msg";

    public R() {
        put(MSG, HttpStatus.OK.getReasonPhrase());
        put(CODE, HttpStatus.OK.value());
    }

    public static R ok() {
        return new R();
    }

    public static R ok(String msg) {
        R r = new R();
        r.put(MSG, msg);
        return r;
    }

    public static R ok(Map<String, Object> map){
        R r = new R();
        r.putAll(map);
        return r;
    }

    public static R error(){
        return error(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase());
    }

    public static R error(String msg) {
        R r = new R();
        r.put(MSG, msg);
        return r;
    }

    public static R error(int code, String msg) {
        R r = new R();
        r.put(CODE, code);
        r.put(MSG, msg);
        return r;
    }



}
